import openpyxl
import datetime

# 读取excel
class ReadExcel():

    def __init__(self, file_path):
        self.workbook  = openpyxl.load_workbook(file_path)
        self.worksheet = self.workbook.active

    def get_data(self):
        data = []
        for row in self.worksheet.iter_rows():
            row_value = []
            for cell in row:
                row_value.append(cell.value)
            data.append(row_value)
        return data
    
class WriteExcel():
    
    def __init__(self,file_path, data):
        self.file_path = file_path
        self.data = data
        self.workbook = openpyxl.Workbook()
        self.worksheet = self.workbook.active

    def write_to_excel(self):
        for row in self.data:
            self.worksheet.append(row)
        self.workbook.save(self.file_path)        
    
if __name__ == '__main__':
    # read_excel_obj = ReadExcel(r'C:\Users\黄进杰\Desktop\1年1班.xlsx')
    # result = read_excel_obj.get_data()
    # print(result)

    # data = ['姓名','学号','班级','性别','生日','联系方式','地址']
    data = ['李先念','x54356789','1年1班','男', datetime.dateitme(2001, 9, 3),'12321345654','云南']
    write_excel_obj = WriteExcel(r'G:\acode\studentmanagement\utils\1年1班学生测试.xlsx',data=data)
    write_excel_obj.write_to_excel()